<template>
  <div class="order-particulars">
    <!-- 头部导航 -->
    <div class="header">
      <div class="left" @click="goBack">
        <i class="el-icon-arrow-left"></i>
      </div>
      <div class="title">订单详情</div>
      <div class="right"></div>
    </div>

    <!-- 详情内容 -->
    <div class="detail-content">
      <!-- 患者信息 -->
      <div class="info-section">
        <div class="section-title">患者信息</div>
        <div class="info-list">
          <div class="info-item">
            <span class="label">姓名</span>
            <span class="value">{{ orderInfo.patientName }}</span>
          </div>
          <div class="info-item">
            <span class="label">性别</span>
            <span class="value">{{ orderInfo.sex==1?"男":"女"  }}</span>
          </div>
          <div class="info-item">
            <span class="label">年龄</span>
            <span class="value">{{ orderInfo.age }}岁</span>
          </div>
          <div class="info-item">
            <span class="label">手机</span>
            <span class="value">{{ orderInfo.phone }}</span>
          </div>
        </div>
      </div>

      <!-- 订单信息 -->
      <div class="info-section">
        <div class="section-title">订单信息</div>
        <div class="info-list">
          <div class="info-item">
            <span class="label">问诊单价</span>
            <span class="value price">¥{{ formatMoney(orderInfo.payPrice) }}</span>
          </div>
          <div class="info-item">
            <span class="label">实付款</span>
            <span class="value actual-price">¥{{ formatMoney(orderInfo.actualPrice) }}</span>
          </div>
          <div class="info-item">
            <span class="label">订单编号</span>
            <span class="value">{{ orderInfo.orderNo }}</span>
          </div>
          <div class="info-item">
            <span class="label">创建时间</span>
            <span class="value">{{ orderInfo.createTime }}</span>
          </div>
          <div class="info-item">
            <span class="label">支付时间</span>
            <span class="value">{{ orderInfo.payTime }}</span>
          </div>
          <div class="info-item">
            <span class="label">支付方式</span>
            <span class="value">{{ orderInfo.payType===0 ? '支付宝支付' : orderInfo.payType===1 ? '微信支付' : orderInfo.payType===2 ? '银行卡支付' : orderInfo.payType===3  }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getOrderDetails } from '@/api/myincome/myincome'

export default {
  data() {
    return {
      orderInfo: {
        patientName: '',
        sex: '',
        age: '',
        phone: '',
        consultType: '',
        department: '',
        price: 0,
        discount: 0,
        actualPrice: 0,
        orderNo: '',
        createTime: '',
        payTime: '',
        payMethod: ''
      }
    }
  },
  created() {
    const orderId = this.$route.query.orderId
    console.log(orderId)
    if (orderId) {
      this.getOrderDetail(orderId)
    }
  },
  methods: {
    goBack() {
      this.$router.go(-1)
    },
    formatMoney(value) {
      const num = parseFloat(value || 0)
      return num.toFixed(2)
    },
    async getOrderDetail() {
      const orderId = this.$route.query.orderId
      try {
        const res = await getOrderDetails(orderId)
        if (res) {
          this.orderInfo = res
          console.log(res)
        }
      } catch (error) {
        console.error('获取订单详情失败:', error)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.order-particulars {
  min-height: 100vh;
  background-color: #f5f5f5;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 44px;
  padding: 0 15px;
  background: #fff;
  border-bottom: 1px solid #eee;

  .title {
    font-size: 17px;
    font-weight: 500;
  }

  .left {
    cursor: pointer;
  }
}

.detail-content {
  padding: 15px;
}

.info-section {
  background: #fff;
  border-radius: 8px;
  padding: 15px;
  margin-bottom: 15px;

  .section-title {
    font-size: 16px;
    font-weight: 500;
    color: #333;
    margin-bottom: 15px;
  }

  .info-list {
    .info-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 10px 0;
      font-size: 14px;
      border-bottom: 1px solid #f5f5f5;

      &:last-child {
        border-bottom: none;
      }

      .label {
        color: #666;
      }

      .value {
        color: #333;

        &.price {
          color: #FF4949;
        }

        &.discount {
          color: #67C23A;
        }

        &.actual-price {
          color: #FF4949;
          font-weight: 500;
        }
      }
    }
  }
}
</style>
